#include "SeqDeque.h"

bool enQueueHead(SeqDeque& Q, DQElemType x)
{
	if ((Q.end2 + 1) % maxSize == Q.end1)
	{
		return false;
	}
	Q.end1 = (Q.end1 - 1 + maxSize) % maxSize;
	Q.elem[Q.end1] = x;
	return true;
}

bool deQueueHead(SeqDeque& Q, DQElemType& x)
{
	if (Q.end1 == Q.end2)
	{
		return false;
	}
	x = Q.elem[Q.end1];
	Q.end1 = (Q.end1 + 1) % maxSize;
	return true;
}

bool getHead(SeqDeque& Q, DQElemType& x)
{
	if (Q.end1 == Q.end2)
	{
		return false;
	}
	x = Q.elem[Q.end1];
	return true;
}

bool enQueueTail(SeqDeque& Q, DQElemType x)
{
	if ((Q.end2 + 1) % maxSize == Q.end1)
	{
		return false;
	}
	Q.elem[Q.end2] = x;
	Q.end2 = (Q.end2 + 1)% maxSize;
	return true;
}

bool deQueueTail(SeqDeque& Q, DQElemType& x)
{
	if (Q.end1 == Q.end2)
	{
		return false;
	}
	Q.end2 = (Q.end2 - 1 + maxSize) % maxSize;
	x = Q.elem[Q.end2];
	return true;
}

bool getTail(SeqDeque& Q, DQElemType& x)
{
	if (Q.end1 == Q.end2)
	{
		return false;
	}
	x = Q.elem[(Q.end2 - 1 + maxSize) % maxSize];
	return true;
}